#[derive(Debug)]
enum Message {
    Quit,
    Move { x: i32, y: i32 }, // 匿名结构体
    Write(String),
    ChangeColor(i32, i32, i32),
}

// 为枚举定义方法
impl Message {
    fn call(&self) {
        println!("Message called: {:#?}", self)
    }
}


fn main() {
    let m = Message::Write(String::from("hello"));
    m.call();
    match m {
        Message::Quit => println!("quit"),
        Message::Move { x, y} => println!("move x:{}, y:{}", x, y),
        Message::Write(s) => println!("write {}", s),
        Message::ChangeColor(_, _, _) => println!("change color"),
    }

    // if let 只关心某个匹配结果, 忽略其他匹配
    let m2 = Message::Move { x: 2, y: 100 };
    // 只匹配x为1的结果
    if let Message::Move{ x: 1, y } = m2 {
        println!("move y {}", y)
    } else {
        println!("move other")
    }
    
}